import React, { Component } from "react";
import store from './store/transit'
import axios from "axios";

import { CHANGE_BANNER_LIST, CHANGE_PRO_LIST } from "./store/types";

export default class Page1 extends Component {

    componentDidMount() {
        axios.get('http://121.89.205.189:3000/api/pro/list').then(res=>{
            console.log(res.data.data);
            store.dispatch({type: CHANGE_PRO_LIST, payload: res.data.data})
        })

        axios.get('http://121.89.205.189:3000/api/banner/list').then(res=>{
            // console.log(res.data.data);
            store.dispatch({type: CHANGE_BANNER_LIST, payload: res.data.data})
        })
    }
    render() {
        
        const countNum = store.getState().count.count;
        
        return <>
            <h1>Page1 -- {countNum}</h1>
            <button onClick={()=>{ 
                store.dispatch({type: 'add'})
            }}>点击加1</button>

            <ul>
                { store.getState().pro.proList.map((item) => {
                    return <li key={item.proid}>{item.proname}</li>
                })}
            </ul>

        </>
    }
}